<template>
    <view>
        <template v-for="(item, index) in pageObj.list">
            <view class="messageContainer"  :key="item.id" @click="gotoCustomerDetail(item.userId)">
                <image class="avatar" :src="item.avatar" mode=""></image>
                <!-- <image class="avatar"  src="@/static/img/user_img_ntx.png" mode=""></image> -->
                <view class="wrapper">
                    <view class="top">
                        <view class="left text-1line-ellipsis">
                            {{item.nickname||'...'}} 
                        </view>
                        <view class="right">
                            {{item.createTime}}
                        </view>
                    </view>
                    <view class="bottom">
                        <view class="left">
                            {{item.content||''}}
                        </view>

                        <view style="width: 5rpx;">
                            
                        </view>
                    </view>
                </view>
            </view>
        </template>
    </view>
</template>

<script>
    import {
        mapState,
        mapMutations,
        mapActions
    } from 'vuex';
    const App = getApp();
    const api = require("@/static/js/api.js")
    const utils = require("@/static/js/utils.js")
    let that = null
    export default {
        data() {
            return {
                pageObj: {
                    list: [],
                    loadStatus: "loading",
                    pageIndex: 1,
					curPageIndex: 0,
                },
            };
        },
        onLoad() {
            that = this
            that.getAllCustomerLogList();
        },
        onShow() {
            
        },
        onUnload(){
            
        },
        onHide() {
            
        },
        onReachBottom() {
            that.getAllCustomerLogList();
        },
        methods:{
            gotoCustomerDetail(id){
				if (this.isReferrer||this.isChannel){
				    return;
				}
                uni.navigateTo({
                    url:'./customerDetail?id='+id
                })
            },
            
            getAllCustomerLogList() {
                let that = this
				if (that.pageObj.curPageIndex != that.pageObj.pageIndex){
					that.pageObj.curPageIndex = that.pageObj.pageIndex
					api.getAllCustomerLogList({
					    param: {
					        limit: 10,
					        page: that.pageObj.pageIndex,
					    }
					}).then(res => {
					    console.log(res)
					    if (res.code==0) {          
					        that.pushListShow(that.pageObj, res.data)         
					    }
					})
				}
            },
            /**
             * @description: 列表中添加数据
             * @param {number} id   u-tabs-swiper的当前ID
             * @param {list}  列表
             * @return void
             */
            pushListShow(srcObj, pushlist) {
                if (pushlist && pushlist.length > 0) {
                    for (let i = 0; i < pushlist.length; i++) {
                        pushlist[i].allTimes = pushlist[i].allTimes || ''
                        pushlist[i].date = pushlist[i].date || ''
                        pushlist[i].avatar = pushlist[i].avatar || ''
                        pushlist[i].nickname = pushlist[i].nickname || ''
                        if (pushlist[i].lastUserLog&&pushlist[i].lastUserLog.createTime){
                            var date = utils.formatTime(pushlist[i].lastUserLog.createTime, "yyyy-MM-dd")  
                            pushlist[i].introduce = date + '，' + (pushlist[i].lastUserLog.content||'');
                        }else{
                            pushlist[i].introduce = "暂无记录"
                        }
                        
                        srcObj.list.push(pushlist[i])
                    }
                    srcObj.pageIndex++;
            
                    if (pushlist.length == 10) {
                        srcObj.loadStatus = "loadmore"
                    } else {
                        srcObj.loadStatus = "nomore"
                    }
                } else {
                    srcObj.loadStatus = "nomore"
                }
            },
            
            //----清空列表
            clearListShow(srcObj) {
				srcObj.curPageIndex = 0;
                srcObj.pageIndex = 1;
                srcObj.list.splice(0, srcObj.list.length)
            },
        }
        
    }
</script>

<style lang="scss">
    page{
        background-color: #F3F3F3;
    }
    .messageContainer{
        margin-top: 1px;
        margin-bottom: 1px;
        width: 750rpx;
        // height: 150rpx;
        background-color: #FFFFFF;
        display: flex;
        align-items: center;
		padding: 30rpx 0;
        .avatar{
            width: 98rpx;
            height: 98rpx;
            margin-left: 30rpx;
            margin-right: 23rpx;
            border-radius: 50%;
            overflow: hidden;
			background-color: #F3F3F3;
        }
        .wrapper{
            width: 560rpx;
            .top{
                display: flex;
                justify-content: space-between;
				align-items: center;
                .left{
					height: 40rpx;
                    width: 250rpx;
                   	font-size: 32rpx;
					line-height: 40rpx;
                   	color: #121212; 
                }
                .right{
                    font-size: 26rpx;
                    color: #999999;
                }
            }
            .bottom{
                // height: 36rpx;
                display: flex;
                justify-content: space-between;
                margin-top: 20rpx;
                .left{
                    width: 435rpx;
                    font-size: 26rpx;
                    font-weight: normal;
                    font-stretch: normal;
                    letter-spacing: 0rpx;
                    color: #999999;
                }
                .right{
                    // width: 44rpx;
                    min-width: 36rpx;
                    padding: 0 10rpx;
                    height: 36rpx;
                    background-color: #ff4547;
                    border-radius: 18rpx;
                    font-size: 24rpx;
                    font-weight: normal;
                    font-stretch: normal;
                    letter-spacing: 0rpx;
                    color: #ffffff;
                    line-height: 36rpx;
                    text-align: center;
                }
            }
        }
    }
    
</style>
